﻿@using LanDBom.Resources
@{
    ViewBag.Title = "Contracts_statement";
}
@section styles{
    <style>
        input{
            width:100%;
        }
        fieldset{
            
        }
        fieldset div{
            margin-bottom:5px
        }
        #finddiv1 {
            width: 100%;
        }
        select{
            width:100%;
        }
        #viewdiv {
            width: 100%;
            overflow: scroll;
            height: 500px;
        }
        #btable {
            width:150%;
        }
            #btable tr td, #btable thead tr th {
                width: 150px;
            }
    </style>
}
<from>
    
    <div id="WT_dh_mb2" style="display: none; position: absolute; border: 1px black solid; left: 25%; top: 33%; background-color: white; background-color: #f1f1f1;height:200px;width:300px">
        <div style="text-align: right; background-color: #84acde;"><span class="WT_qxbh2" style=" margin: 20px;"><i class="bi bi-x-square"></i></span></div>
        <div style="margin: 20px 10px; padding: 10px; background-color: #fff;">
            <div id="WJ_XZLJ"></div>
        </div>
        <div style="text-align:center"><button class="WT_qxbh2">@Resource.String126</button></div>
    </div>
    <div id="finddiv1">
        <fieldset class="boun">
            <legend class="len"></legend>
            <div class="row">
                <div class="col-1">发起时间</div>
                <div class="col-1">从</div>
                <div class="col-2"><input type="date" id="FQSJ_C" /></div>
                <div class="col-1">到</div>
                <div class="col-2"><input type="date" id="FQSJ_D" /></div>
                <div class="col-5"></div>

                <div class="col-1">@Resource.String586</div>
                <div class="col-2"><input type="text" id="BB_WT_sqdh" /></div>
                <div class="col-1">@Resource.String587</div>
                <div class="col-2"><input type="text" id="BB_WT_xmmc" /></div>
                <div class="col-1">@Resource.String591</div>
                <div class="col-2">
                    <select id="BB_WT_dj" class="input-au">
                        <option value="">@Resource.String592</option>
                        <option value=A>A</option>
                        <option value=B>B</option>
                        <option value=C>C</option>
                        <option value=D>D</option>
                    </select>
                </div>
                <div class="col-1">@Resource.String593</div>
                <div class="col-2 ">
                    <select id="BB_WT_zt" class="input-au">
                        <option value="">@Resource.String594</option>
                        <option value=1>项目完成</option>
                        <option value=2>项目执行中</option>
                        <option value=3>项目结束</option>
                    </select>
                </div>

                
            </div>
            <div style="text-align:center">
                <button id="BB_WT_cx" style="width:100px">查询信息</button>
                &emsp;&emsp;
                <button id="BB_WT_scbb"style="width:100px">生成报表</button>
            </div>
        </fieldset>
    </div>
    <div style="height:70vh;overflow-x:scroll;overflow-y:hidden">
        <table id="btable" class=" tab table" style="text-align-last:left">
            <thead>
                <tr>
                    <th scope="col" style="width:36px;"><input type="checkbox" id="quanxuan"/></th>
                    <th scope="col" style="width:50px;">@Resource.String1000</th>
                    <th scope="col">@Resource.String602</th>
                    <th scope="col">@Resource.String603</th>
                    <th scope="col">@Resource.String821</th>
                    <th scope="col">@Resource.String604</th>
                    <th scope="col">@Resource.String605</th>
                    <th scope="col">@Resource.String606</th>
                    <th scope="col">@Resource.String607</th>
                    <th scope="col">@Resource.String608</th>
                    <th scope="col">@Resource.String609</th>
                    <th scope="col">@Resource.String610</th>
                    <th scope="col">@Resource.String611</th>
                    <th scope="col">@Resource.String612</th>
                    <th scope="col">@Resource.String613</th>
                    <th scope="col">@Resource.String614</th>
                    <th scope="col">设计要求</th>
                    <th scope="col">@Resource.String616</th>
                    <th scope="col">@Resource.String617</th>
                    <th scope="col">@Resource.String618</th>
                    <th scope="col">其他要求或信息</th>
                    <th scope="col">@Resource.String620</th>
                    <th scope="col">@Resource.String621</th>
                    <th scope="col">@Resource.String622</th>
                    <th scope="col">@Resource.String623</th>
                    <th scope="col">@Resource.String624</th>
                    <th scope="col">@Resource.String625</th>
                    <th scope="col">@Resource.String626</th>
                    <th scope="col">@Resource.String627</th>
                    <th scope="col">项目进展状态</th>
                </tr>
            </thead>
            <tbody data-spy="scroll" id="BB_WT_tb" style="height:590px">
            </tbody>
        </table>
    </div>
    @Html.ActionLink("返回", "Inspect_Contracts", "Contracts", new { @class = "btn" })
</from>


@section scripts
{
    <script src="~/Scripts/jquery-3.4.1.min.js"></script>
    <script src="~/Scripts/bootstrap.min.js"></script>
    <script>
        $(function () {
            $("#li15").css({ "color": "black", "background-color": "white" })
            get_contracts()
            Generate_report()

            $(document).on("click", "#BB_WT_cx", function () {
                get_contracts()
            })
            $(document).on("click", "#quanxuan", function () {
                if ($("#quanxuan").prop("checked") == true) {
                    console.log(1)
                    $(".zishhg").prop("checked", true)
                }
                else {
                    $(".zishhg").prop("checked", false)
                }
            })
            function get_contracts() {
                var cong = $("#FQSJ_C").val()
                var dao = $("#FQSJ_D").val()
                var BB_WT_id = $("#BB_WT_id").val()
                var BB_WT_sqdh = $("#BB_WT_sqdh").val()
                var BB_WT_dj = $("#BB_WT_dj").val()
                var BB_WT_zt = $("#BB_WT_zt").val()
                var BB_WT_xmmc = $("#BB_WT_xmmc").val()
                $.ajax({
                    url: '/Contracts/Contracts_statement',
                    type: 'POST',
                    data: { "BB_WT_id": BB_WT_id, "BB_WT_sqdh": BB_WT_sqdh, "BB_WT_dj": BB_WT_dj, "BB_WT_zt": BB_WT_zt, "BB_WT_xmmc": BB_WT_xmmc, "cong": cong, "dao": dao, "state": 1 },
                    success: function (dataT) {
                        console.log(dataT)
                        newWT(dataT)
                    },
                    error: function () {
                        alert('Request Error');
                    }
                })
            }
            
            function newWT(wt) {
                console.log(wt)
                $('#BB_WT_tb tr').remove();
                $.each(wt, function (i, item) {
                  
                    var $zc = $(`
                        <tr >
                            <td scope="col" style="width:36px;"><input type="checkbox" class="zishhg" name="jhfljls" /></td>
                            <td scope="col" id="WT_SJ_S1" style="width:50px;">${item.D_id}</td>
                            <td scope="col" id="${item.D_Applic}"><div id="WT_SJ_S2">${item.D_Applic}</div></td>
                            <td scope="col" id="WT_SJ_S3">${item.D_reDate}</td>
                            <td scope="col" id="WT_SJ_S29">${item.DFToDate}</td>
                            <td scope="col" id="WT_SJ_S4">${item.D_take}</td>
                            <td scope="col" id="WT_SJ_S5">${item.D_App}</td>
                            <td scope="col" id="WT_SJ_S6">${item.D_AppRevi}</td>
                            <td scope="col" id="WT_SJ_S7">${item.D_Ton}</td>
                            <td scope="col" id="WT_SJ_S8">${item.D_CN}</td>
                            <td scope="col" id="WT_SJ_S9">${item.D_PN}</td>
                            <td scope="col" id="WT_SJ_S10">${item.D_DE}</td>
                            <td scope="col" id="WT_SJ_S11">${item.D_LV}</td>
                            <td scope="col" id="WT_SJ_S12">${item.D_DT}</td>
                            <td scope="col" id="WT_SJ_S13">${item.D_PW}</td>
                            <td scope="col" id="WT_SJ_S14">${item.D_SI}</td>
                            <td scope="col" id="WT_SJ_S15" ><textarea>${item.D_OI}</textarea></td>
                            <td scope="col" id="WT_SJ_S16">${item.D_MOF}</td>
                            <td scope="col" id="WT_SJ_S17">${item.D_PT}</td>
                            <td scope="col" id="WT_SJ_S18">${item.D_PR}</td>
                            <td scope="col" id="WT_SJ_S19"><textarea>${item.D_OR}</textarea></td>
                            <td scope="col" id="WT_SJ_S20"><textarea>${item.D_SR}</textarea></td>
                            <td scope="col" id="WT_SJ_S21">${item.D_PA}</td>
                            <td scope="col" id="WT_SJ_S22">${item.D_REC}</td>
                            <td scope="col" id="WT_SJ_S23">${item.D_AR}</td>
                            <td scope="col" id="WT_SJ_S24">${item.D_CD}</td>
                            <td scope="col" id="WT_SJ_S25">${item.D_TCA}</td>
                            <td scope="col" id="WT_SJ_S28">${item.D_price}</td>
                            <td scope="col" id="WT_SJ_S26"" class="rz"><textarea id="${item.D_id}"></textarea></td>
                            <td scope="col" id="WT_SJ_S27">${item.D_JL}</td>
                        </tr>
                    `);
                    $('#BB_WT_tb').append($zc);

                    $.ajax({
                        url: '/Contracts/Contracts_statement',
                        type: 'GET',
                        data: { "BB_WT_sqdh": item.D_Ton , "state": 2 },
                        success: function (rz) {
                            addrz(rz)
                        },
                        error: function () {
                            alert('Request Error');
                        }
                    })
                    function addrz(rz) {
                        $("div[id=" + item.D_id + "] div").remove()
                        $("div[id=" + item.D_id + "] hr").remove()
                        $.each(rz, function (index, obj) {
                            var $div = $(`
                            <div>${obj.B_Date} ${obj.B_BR}:${obj.B_bei}</div>
                            </hr>
                            `);
                            $("div[id=" + item.D_id + "]").append($div)
                        })
                    }
                })
            }

            function Generate_report() {
                $(document).on("click", "#BB_WT_scbb", function () {
                    var CG_XX = [];
                    var WT_RZ = [];
                    var check = $("input[type=checkbox]:checked").parent().parent().length;
                    if (check < 0) {
                        alert(0);
                    }
                    else {
                        $("input[name=jhfljls]:checked").parent().parent().each(function (index, obj) {
                            CG_XX.push({
                                D_id: $("td[id='WT_SJ_S1']", obj).text(),
                                D_Applic: $("div[id='WT_SJ_S2']", obj).text(),
                                D_reDate: $("td[id='WT_SJ_S3']", obj).text(),
                                D_take: $("td[id='WT_SJ_S4']", obj).text(),
                                D_App: $("td[id='WT_SJ_S5']", obj).text(),
                                D_AppRevi: $("td[id='WT_SJ_S6']", obj).text(),
                                D_Ton: $("td[id='WT_SJ_S7']", obj).text(),
                                D_CN: $("td[id='WT_SJ_S8']", obj).text(),
                                D_PN: $("td[id='WT_SJ_S9']", obj).text(),
                                D_DE: $("td[id='WT_SJ_S10']", obj).text(),
                                D_LV: $("td[id='WT_SJ_S11']", obj).text(),
                                D_DT: $("div[id='WT_SJ_S12']", obj).text(),
                                D_PW: $("td[id='WT_SJ_S13']", obj).text(),
                                D_SI: $("td[id='WT_SJ_S14']", obj).text(),
                                D_OI: $("td[id='WT_SJ_S15']", obj).children().val(),
                                D_MOF: $("td[id='WT_SJ_S16']", obj).text(),
                                D_PT: $("div[id='WT_SJ_S17']", obj).text(),
                                D_PR: $("td[id='WT_SJ_S18']", obj).text(),
                                D_OR: $("td[id='WT_SJ_S19']", obj).children().val(),
                                D_SR: $("td[id='WT_SJ_S20']", obj).children().val(),
                                D_PA: $("td[id='WT_SJ_S21']", obj).text(),
                                D_REC: $("div[id='WT_SJ_S22']", obj).text(),
                                D_AR: $("td[id='WT_SJ_S23']", obj).text(),
                                D_CD: $("td[id='WT_SJ_S24']", obj).text(),
                                D_TCA: $("td[id='WT_SJ_S25']", obj).text(),
                                D_price: $("td[id='WT_SJ_S28']", obj).text(),
                                D_kong: $("td[id='WT_SJ_S26']", obj).text(),
                                D_zhuang: $("td[id='WT_SJ_S27']", obj).text(),
                                DFToDate: $("td[id='WT_SJ_S29']", obj).text(),
                            })
                            //WT_RZ.push({
                            //    B_bei: $("div[id='WT_SJ_S26']")
                            //})
                            console.log("共" + CG_XX.length + "数据");
                            console.log(CG_XX);
                        })
                        if (CG_XX.length == 0) {
                            alert("请勾选需要生成的行")
                        }
                        else {
                            var Employee_path = $("#Login_path").text()
                            console.log(Employee_path)
                            var userInput = prompt("请输入文件名：", "");
                            if (userInput != null) {
                                $.ajax({
                                    url: "/Contracts/DownloadExcel",
                                    type: 'POST',
                                    data: { "Designdraws": CG_XX, "WT_CD": CG_XX.length, "state": 1, "excelName": userInput, "Employee_path": Employee_path },
                                    success: function (text) {
                                        $("#WT_dh_mb2").css({ "display": "block" })
                                        $("#WJ_XZLJ").append($(`<a href="/Contracts/Download_file?path=${text}" id="log_SZ" class="WT_qxbh2">下载</a>`))
                                    },
                                    error: function (text) {
                                        alert("系统错误" + text);
                                    }
                                })
                            }
                        }
                    }
                })
            }
            $(document).on("click", ".WT_qxbh2", function () {
                $("#WT_dh_mb2").css({ "display": "none" })
                $("#WJ_XZLJ a").remove()
            })
            /*function fenye(a) {
                a = a == 0 ? "1" : a
                var hjin = a * 1
                var shunddd = $("#komdr").text() * 1
                $(".pagination li").remove()
                var $ul = ""
                $ul += (`<li class="page-item"><span class="page-link shiyong"><<<</span></li>`)
                for (var i = 1; i <= shunddd; i++) {
                    if (shunddd < 4) {
                        if (i < 5) {
                            if (hjin == i) {
                                $ul += "<li class='page-item'><span class='page-link shiyong' id='shiyongll' style='background-color:#c4ded9'>" + i + "</span></li>";
                            } else {
                                $ul += "<li class='page-item'><span class='page-link shiyong'>" + i + "</span></li>";
                            }
                        } else {
                            $ul += "<li class='page-item'><span class='page-link'>.....</span></li>";
                            break
                        }
                    }
                    if (shunddd >= 4) {
                        if (i < (hjin - 2) || i >= (hjin + 2)) {
                            continue
                        }
                        if (i > (hjin - 2) && i < (hjin + 2)) {
                            if (hjin == i) {
                                $ul += "<li class='page-item'><span class='page-link shiyong' id='shiyongll' style='background-color:#c4ded9'>" + i + "</span></li>";
                            } else {
                                $ul += "<li class='page-item'><span class='page-link shiyong'>" + i + "</span></li>";
                            }
                        } else {
                            $ul += "<li class='page-item'><span class='page-link'>.....</span></li>";
                        }
                    }
                }
                $ul += (`<li class="page-item"><span class="page-link shiyong">>>></span></li>`);
                $(".pagination").append($ul)
            }*/
            /*$(document).on("click", ".shiyong,.subsed", function () {
                var sjind = $(this).text()
                var shunddd = $("#komdr").text()
                sjind = sjind == "<<<" ? 1 : sjind == ">>>" ? shunddd : sjind * 1
                get_contracts(sjind)
            })*/
        })
    </script>
}